/**
 * 
 */
package com.p2p.front.task;

import java.util.Date;
import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.p2p.base.cache.Cache;
import com.p2p.base.redis.RedisClient;
import com.p2p.front.service.impl.LoanVariationServiceImpl;

/**
 * @author ruiqi
 *
 */
public abstract class BaseTask {
	protected final Logger logger = LoggerFactory.getLogger(BaseTask.class);
	
	@Resource
	private Cache defaultCache;
	
	/**
	 * @param bizKey   //任务的bizKey
	 * @param second   //保持同步持续时间，单位秒
	 * @return
	 */
	public boolean doTaskSynchronous(String bizKey,long second){
		
		boolean bool = defaultCache.setIfAbsent(bizKey, new Date(), second);
		logger.info("doTaskSynchronous "+bool+",bizKey="+bizKey);
		return bool;
	}
	
	public void doRmoveTaskSynchronous(String bizKey){
		logger.info("doRmoveTaskSynchronous,bizKey="+bizKey);
		defaultCache.delete(bizKey);
	}

	public abstract String getBizKey();
	
	public abstract void doBiz();
	
}
